package com.ieheima.zuoye5;

import java.util.Comparator;
import java.util.TreeSet;

public class Test {
    public static void main(String[] args) {
        TreeSet<Student> ts = new TreeSet<>((s1,s2)->{
            int sum = s1.getChemistry()+s1.getPhysic();
            int sum1 = s2.getChemistry()+s2.getPhysic();
            if (sum1==sum){
                return s2.getChemistry()-s1.getChemistry();
            }
           return sum1-sum;
        });

        ts.add(new Student("爱迪生", 90, 55));
        ts.add(new Student("牛顿", 100, 90));
        ts.add(new Student("拉瓦锡", 70, 100));
        ts.add(new Student("霍金", 100, 100));
        ts.add(new Student("伽利略", 60, 85));
        ts.add(new Student("达尔文", 70, 75));
        ts.forEach(student -> System.out.println(student));

    }
}
